<template>
  <!--  活动审核页面-->
  <div id="top">
    <div>
      <el-card id="search">
        <el-input v-model="actInfo" placeholder="请输入活动名称"></el-input>
        <el-button type="primary" plain @click="getactInfo()">查询</el-button>
        <el-button type="danger" plain @click="doshenhe()">审核</el-button>
        <el-button type="danger" plain @click="dontPass()">查看未通过</el-button>
      </el-card>
    </div>
    <el-row>
      <el-table :data="currentPageData" stripe style="width: 100%">
        <el-table-column prop="vid" label="活动ID" width="230"/>
        <el-table-column prop="user.uname" label="发起人" width="270"/>
        <el-table-column prop="vtitle" label="活动名称" width="370"/>
<!--        <el-table-column prop="vaddress" label="活动地点" width="310"/>-->
        <el-table-column prop="createdate" label="时间" width="400"/>
        <el-table-column fixed="right" label="操作" width="230">
          <template #default="scope">
            <el-button link type="primary" size="small" @click="viewDetall(scope.row)" v-show="bangzhu">
              查看报名用户
            </el-button>
            <el-button link type="primary" size="small" v-show="shenhe" @click="viewLook(scope.row)">
              查看详情
            </el-button>
            <el-button link type="primary" size="small" v-show="shenhe" @click="viewPass(scope.row)">
              通过
            </el-button>
            <el-button link type="primary" size="small" v-show="shenhe" @click="viewDont(scope.row)">
              不通过
            </el-button>
            <div v-show="wtg">未通过</div>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <!--  分页组件-->
    <el-pagination
        v-model="currentPage"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="totalData.length"
        @current-change="handleCurrentChange">
    </el-pagination>
  </div>

  <!--  查看-->
  <el-dialog
      v-model="dialogVisible"
      title="报名用户"
      width="30%"
      :before-close="handleClose">
    <table>
      <tr v-for="item in userList" :key="item.vid">
        <td>报名人：</td>
        <td>{{ item.user.uname }}</td>
        <td>&nbsp;&nbsp;&nbsp;</td>
        <td>报名时间：</td>
        <td>{{ item.createdate }}</td>
      </tr>
    </table>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible=false">取消</el-button>
        <el-button type="primary" @click="dialogVisible=false">确定</el-button>
      </span>
    </template>
  </el-dialog>

  <!--审核查看-->
  <el-dialog
      v-model="dialogVisibleshenhe"
      title="活动详情"
      width="60%"
      height="30%"
      :before-close="handleClose">
    <table style="width: 600px">
      <tr>
        <td style="height: 35px;width: 70px">标题：</td>
        <td>{{ activitys.vtitle }}</td>
      </tr>

      <tr>
        <td style="height: 50px;width: 70px">副标题：</td>
        <td>{{ activitys.vsubhead }}</td>
      </tr>

      <tr>
        <td style="height: 35px;width: 70px">内容：</td>
        <td>
          <div v-html=" activitys.vdetail "></div>
        </td>
      </tr>

      <tr>
        <td style="height: 35px;width: 70px">地址：</td>
        <td>
          <p>{{ realAdd }}</p>
          <div class="drawStation">
            <div id="draw-station-container">
            </div>
          </div>
        </td>
      </tr>
    </table>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisibleshenhe=false">取消</el-button>
        <el-button type="primary" @click="dialogVisibleshenhe=false">确定</el-button>
      </span>
    </template>
  </el-dialog>

</template>

<script>

import doThis from "@/api/getData";
import * as AMapLoader from "@amap/amap-jsapi-loader";
import axios from "axios";

export default {
  name: "ActivityList",
  data() {
    return {
      actInfo: '',
      actList: [],
      dialogVisible: false,
      dialogVisibleshenhe: false,
      userList: [],
      users: {},
      activitys: {},
      shenhe: false,
      bangzhu: true,
      wtg:false,
      //分页
      tableData: [], // 总数据
      totalData: [], // 总数据
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页显示的条数

      // 地图对象
      // 地图实例对象
      map: null,
      // 标点对象
      marker: null,
      realAdd: null,
    }
  },
  mounted() {
    this.getActList()
  },
  computed: {
    // 根据当前页面和每页显示的条数，计算分页后的数据
    currentPageData() {
      const {totalData, currentPage, pageSize} = this;
      const start = (currentPage - 1) * pageSize;
      const end = start + pageSize;
      return totalData.slice(start, end);
    },
  },
  methods: {

    initMap(x, y) {
      console.log(x, y)
      AMapLoader.load({
        key: '105771500d5f91b00104a0d28ea72c41', // 申请好的Web端开发者Key，首次调用 load 时必填
        version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
        plugins: ['AMap.Scale', 'AMap.PlaceSearch', 'AMap.AutoComplete'], // 需要使用的的插件列表，如比例尺'AMap.Scale'等
      })
          .then((AMap) => {
            this.map = new AMap.Map("draw-station-container", {
              resizeEnable: true,
              //设置地图容器id
              viewMode: "3D", //是否为3D地图模式
              zoom: 15, //初始化地图级别
              center: [x, y], //初始化地图中心点位置
              // mapStyle: 'amap://styles/macaron', //设置地图的显示样式
            })
            // 地图点击事件
            new AMap.Marker({
              map: this.map,
              position: [x, y],
            })
          })
      axios.get("https://restapi.amap.com/v3/geocode/regeo", {
        params: {
          output: 'json',
          location: x + ',' + y,
          key: 'f5e5504bd7700d7045245f8b7ca45b29',
          radius: '1000',
          extensions: 'all'
        }
      }).then(res => {
        this.realAdd = res.data.regeocode.formatted_address
      })
    },

    // 切换页码时的回调函数
    handleCurrentChange(page) {
      this.currentPage = page;
    },
    //查群通过审核的新闻
    getActList() {
      doThis.doGet("/volunteer/ming", {vstatus: 2}).then(res => {
        console.log("查询全部---------", res.data)
        // this.actList=res.data
        this.tableData = res.data
        this.totalData = res.data
      })
    },
         //搜索
    getactInfo() {
      console.log(this.actInfo)
      doThis.doGet("/volunteer/ming", {vtitle: this.actInfo,vstatus: 2}).then(res => {
        console.log("查询活动-------", res.data)
        // this.actList=res.data
        this.wtg=false
        this.shenhe=false
        this.bangzhu=true
        this.tableData = res.data
        this.totalData = res.data
      })
    },
    //按照ID查报名用户
    getUserList(vid) {
      doThis.doGet("/volunteer/list", {vid: vid}).then(res => {
        console.log("456======", res.data)
        this.userList = res.data.volunteerpeopleList
      })
    },
    //查看报名用户
    viewDetall(row) {
      this.users = row
      this.getUserList(row.vid)
      this.dialogVisible = true
    },
    //查看待审核用户
    doshenhe() {
      doThis.doGet("/volunteer/ming", {vstatus: 1}).then(res => {
        console.log("审核页面-----", res)
        this.wtg=false
        this.shenhe = true
        this.bangzhu = false
        this.tableData = res.data
        this.totalData = res.data
      })
    },
    //通过审核
    viewPass(row) {
      if (confirm("确定要通过吗")) {
        doThis.doGet("/volunteer/update", {vid: row.vid, vstatus: 2}).then(res => {
          console.log("通过----", res.data)
          // this.tableData = res.data
          // this.totalData = res.data
          this.getActList()
        })
      }
    },
    //不通过审核
    viewDont(row) {
      if (confirm("确定要不通过吗")) {
        doThis.doGet("/volunteer/update", {vid: row.vid, vstatus: 6}).then(res => {
          console.log("不通过----", res.data)
          // this.tableData = res.data
          // this.totalData = res.data
          this.getActList()
        })
      }
    },
    //查看待审核详情信息
    viewLook(row) {
      this.activitys = row
      // this.getHelpList(row.aid)
      this.dialogVisibleshenhe = true
      this.initMap(parseFloat(row.vaddress.split(',')[0]), parseFloat(row.vaddress.split(',')[1]))
    },
    //查看未通过
    dontPass(){
      doThis.doGet("/volunteer/ming", {vstatus: 6}).then(res => {
        console.log("审核页面-----", res)
        this.wtg=true
        this.shenhe = false
        this.bangzhu = false
        this.tableData = res.data
        this.totalData = res.data
      })
    }
  },
  beforeUnmount() {
/*    console.log()
    this.map.destroy('beforeUnmount running');
    this.map = null
    this.marker = null*/
  }
}
</script>

<style scoped>
#top {
  margin-top: 47px;
  margin-left: -30px;
  background-color: #EBEBEB;
}

#search .el-input {
  width: 200px;
  margin-left: 30px;
  margin-right: 30px;
}

#search .el-button {
  margin-left: 30px;
  margin-right: 30px;
}

.drawStation #draw-station-container {
  padding: 0;
  /* margin: 20px 0 20px 0; */
  margin: 50px auto;
  width: 500px;
  height: 300px;
}
</style>